module dungeon.potion;

import nade.ast;
import nade.loader;

import dungeon.game;
import dungeon.stats;
import dungeon.item;
import dungeon.character;


class Potion : Item, IUsableItem {
	this(Game game)
	{
		super(game);

		_statsModified = new Stats();
		_statsGiven = new Stats();
	}

	override bool use(Character character)
	{
		character.modify(_statsGiven);
		character.addBuff(_name, _sprite, _statsModified, _duration);

		return true;
	}

	Stats statsModified() { return _statsModified; }
	Stats statsGiven() { return _statsGiven; }

	protected {
		real			_duration = 0;
		real			_fadeInTime = 0;
		real			_fadeOutTime = 0;
		Stats			_statsModified;
		Stats			_statsGiven;
	}

	static void install()
	{
		Loader!(Potion).add("duration",
			(ref Potion potion, AST ast, Object[string] state) {
				potion._duration = ast[0].as!real;
			}
		);

		Loader!(Potion).add("fadeInTime",
			(ref Potion potion, AST ast, Object[string] state) {
				potion._fadeInTime = ast[0].as!real;
			}
		);

		Loader!(Potion).add("fadeOutTime",
			(ref Potion potion, AST ast, Object[string] state) {
				potion._fadeOutTime = ast[0].as!real;
			}
		);

		Loader!(Potion).add("mod",
			(ref Potion potion, AST ast, Object[string] state) {
				potion._statsModified.add(ast[0].as!string, ast[1].as!real);
			}
		);

		Loader!(Potion).add("give",
			(ref Potion potion, AST ast, Object[string] state) {
				potion._statsGiven.add(ast[0].as!string, ast[1].as!real);
			}
		);
	}
}
